package com.cq.controller;


import com.cq.pojo.*;
import com.cq.pojo.dto.MediaSlotPageDTO;
import com.cq.query.PageResultQuery;
import com.cq.result.PageResult;
import com.cq.result.Result;
import com.cq.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/activities")
@RefreshScope
public class ActivityController {

    @Autowired
    private ActivityService activityService;
    @Autowired
    private ActivityMediaSlotAnalysisService activityMediaSlotAnalysisService;
    @Autowired
    private ActivityGroupService activityGroupService;
    @Autowired
    private ActivityPlatformGroupService activityPlatformGroupService;
    @Autowired
    private ActivityPlatformContentGroupService activityPlatformContentGroupService;
    @Autowired
    private ActivityPlatformContentDirectionGroupService activityPlatformContentDirectionGroupService;
    @Autowired
    private ActivityPlatformInfluencergradeGroupService activityPlatformInfluencergradeGroupService;
    @Autowired
    private ActivityPlatformInfluencertypeGroupService activityPlatformInfluencertypeGroupService;
    @Autowired
    private ActivityKolGroupService activityKolGroupService;

    @Value("${upload}")
    private String upload;

    // 查询最新活动列表
    @GetMapping("/fingNewActivitiesListLXF")
    public Result findNewActivities() {
        List<ActivityAnalysis> list = activityService.findNewActivities();

        return Result.success(list);
    }

    // 查询当前活动下的整体投放概览
    @GetMapping("/findAllAnLXF")
    public Result findAllAn(String campaignId) {
        ActivityAnalysis data = activityService.getAlog(campaignId);
        return Result.success(data);
    }

    // 下载excel
    @GetMapping("/downloadLXF")
    public void download(HttpServletResponse response) throws IOException {
        activityService.download(response);
    }

    // 转化数据分析-获取当前活动下的数据
    @GetMapping("/getConversionIncomeLXF")
    public Result getConversionIncome(String campaignId, String status) {
        ConversionIncome data = activityService.getConversionIncome(campaignId,status);
        return Result.success(data);
    }

    // 转化收益分析下载接口
    @GetMapping("/conversionIncomeDownloadLXF")
    public void conversionIncomeDownload(HttpServletResponse response,String campaignId, String status) throws IOException {
        activityService.conversionIncomeDownload(response, campaignId, status);
    }

    // 媒介归因排名-查询触点类型集合
    @GetMapping("/findContactPoint")
    public Result findContactPoint() {
        List<String> list = activityMediaSlotAnalysisService.findContactPoint();
        return Result.success(list);
    }

    // 查询所有媒介归因排名
    @GetMapping("/findMediaSlot")
    public Result findMediaSlot(MediaSlotPageDTO dto) {
        PageResult pageResult = activityService.findMediaSlot(dto);
        return Result.success(pageResult);
    }

    // 媒介归因排名-下载excel
    @GetMapping("/mediaSlotDownload")
    public void mediaSlotDownload(HttpServletResponse response,MediaSlotPageDTO dto) throws IOException {
        activityService.mediaSlotDownload(response, dto);
    }

    @GetMapping("/contactPointDownload")
    public void contactPointDownload(HttpServletResponse response,MediaSlotPageDTO dto) throws IOException {
        activityService.contactPointDownload(response, dto);
    }

    // 查询所有媒介平台
    @GetMapping("/findAllMedia")
    public Result findAllMedia() {
        List<String> list = activityService.findAllMedia();
        return Result.success(list);
    }

    // kol投放
    // 分活动
    @GetMapping("/findSplitActivity")
    public Result findSplitActivity(String campaignName) {
        List<ActivityGroup> list = activityGroupService.findSplitActivity(campaignName);
        return Result.success(list);
    }

    // 分活动分媒介
    @PostMapping("/findActivityPlatformGroup")
    public Result findActivityPlatformGroup(@RequestBody PageResultQuery query) {
        PageResult<ActivityPlatformGroup> list = activityPlatformGroupService.findActivityPlatformGroup(query);
        return Result.success(list);
    }

    @GetMapping("/activityGroupDownload")
    public void activityGroupDownload(HttpServletResponse response,String campaignName) throws IOException {
        activityGroupService.activityGroupDownload(response, campaignName);
    }

    @PostMapping("/activityPlatformGroupDownload")
    public void activityPlatformGroupDownload(@RequestBody PageResultQuery query, HttpServletResponse response) throws IOException {
        activityPlatformGroupService.activityPlatformGroupDownload(response,query);
    }

    @PostMapping("/findActivityPlatformContentGroup")
    public Result findActivityPlatformContentGroup(@RequestBody PageResultQuery query) {
        PageResult<ActivityPlatformContentGroup> data = activityPlatformContentGroupService.findActivityPlatformContentGroup(query);
        return Result.success(data);
    }

    @PostMapping("/activityPlatformContentGroupDownload")
    public void activityPlatformContentGroupDownload(@RequestBody PageResultQuery query,HttpServletResponse response) throws IOException {
        activityPlatformContentGroupService.activityPlatformContentGroupDownload(response, query);
    }

    @PostMapping("/findActivityPlatformContentDirectionGroup")
    public Result findActivityPlatformContentDirectionGroup(@RequestBody PageResultQuery query) {
        PageResult<ActivityPlatformContentDirectionGroup> data = activityPlatformContentDirectionGroupService.findActivityPlatformContentDirectionGroup(query);
        return Result.success(data);
    }

    @PostMapping("/activityPlatformContentDirectionGroupDownload")
    public void activityPlatformContentDirectionGroupDownload(@RequestBody PageResultQuery query,HttpServletResponse response) throws IOException {
        activityPlatformContentDirectionGroupService.activityPlatformContentDirectionGroupDownload(response,query);
    }

    @PostMapping("/findActivityPlatformInfluencergradeGroup")
    public Result findActivityPlatformInfluencergradeGroup(@RequestBody PageResultQuery query) {
        PageResult<ActivityPlatformInfluencergradeGroup> data = activityPlatformInfluencergradeGroupService.findActivityPlatformInfluencegradeGroup(query);
        return Result.success(data);
    }

    @PostMapping("/activityPlatformInfluencergradeGroupDownload")
    public void activityPlatformInfluencergradeGroupDownload(@RequestBody PageResultQuery query,HttpServletResponse response) throws IOException {
        activityPlatformInfluencergradeGroupService.activityPlatformInfluencergradeGroupDownload(response,query);
    }

    @PostMapping("/findActivityPlatformInfluencertypeGroup")
    public Result findActivityPlatformInfluencertypeGroup(@RequestBody PageResultQuery query) {
        PageResult<ActivityPlatformInfluencertypeGroup> data = activityPlatformInfluencertypeGroupService.findActivityPlatformInfluencertypeGroup(query);
        return Result.success(data);
    }

    @PostMapping("/activityPlatformInfluencertypeGroupDownload")
    public void activityPlatformInfluencertypeGroupDownload(@RequestBody PageResultQuery query,HttpServletResponse response) throws IOException {
        activityPlatformInfluencertypeGroupService.activityPlatformInfluencertypeGroupDownload(response, query);
    }

    @PostMapping("/findActivityKolGroup")
    public Result findActivityKolGroup(@RequestBody PageResultQuery query) {
        PageResult<ActivityKolGroup> data = activityKolGroupService.findActivityKolGroup(query);
        return Result.success(data);
    }

    @PostMapping("/activityKolGroupDownload")
    public void activityKolGroupDownload(@RequestBody PageResultQuery query,HttpServletResponse response) throws IOException {
        activityKolGroupService.activityKolGroupDownload(response, query);
    }

    // kol统一下载
    @PostMapping("/kolDownload")
    public void kolDownload(@RequestBody PageResultQuery query, HttpServletResponse response) throws IOException {
        activityKolGroupService.kolDownload(response, query);
    }

    @GetMapping("/findTypeAndCNames")
    public Result findTypeAndCNames() {
        Map<String, List<String>> map = activityService.findTypeAndCNames();
        return Result.success(map);
    }

    // 多活动-核心指标对比
    @GetMapping("/comparisonOfCoreIndicators")
    public Result comparisonOfCoreIndicators(String cidA, String cidB) {
        ActivityAnalysisAndAlogAndDiff data = activityService.comparisonOfCoreIndicators(cidA,cidB);
        return Result.success(data);
    }

    @GetMapping("/comparisonOfCoreIndicatorsDownload")
    public void comparisonOfCoreIndicatorsDownload(String cidA, String cidB, HttpServletResponse response) throws IOException {
        activityService.comparisonOfCoreIndicatorsDownload(cidA, cidB, response);
    }

    // 多活动-分媒介分平台
    @GetMapping("/platformDeliveryComparison")
    public Result platformDeliveryComparison(String cidA, String cidB, String filed) {
        Map<String, Map<String, List<PlatformComparison>>> map = activityMediaSlotAnalysisService.platformDeliveryComparison(cidA, cidB, filed);
        return Result.success(map);
    }

    @GetMapping("/platformDeliveryComparisonDownload")
    public void platformDeliveryComparisonDownload(String cidA, String cidB, String filed,HttpServletResponse response) throws IOException {
        activityMediaSlotAnalysisService.platformDeliveryComparisonDownload(cidA, cidB, filed, response);
    }

    // 分媒介分平台分布
    @GetMapping("/distributionOfSubMediaPlatforms")
    public Result distributionOfSubMediaPlatforms(String cidA, String cidB, String filed) {
        Map<String, Map<String, List<PlatformComparison>>> data = activityMediaSlotAnalysisService.distributionOfSubMediaPlatforms(cidA, cidB, filed);
        return Result.success(data);
    }

    @GetMapping("/distributionOfSubMediaPlatformsDownload")
    public void distributionOfSubMediaPlatformsDownload(String cidA, String cidB, String filed,HttpServletResponse response) throws IOException {
        activityMediaSlotAnalysisService.distributionOfSubMediaPlatformsDownload(cidA, cidB, filed, response);
    }

    // 分媒介分触点类型构成
    @GetMapping("/contactTypeComposition")
    public Result contactTypeComposition(String cidA, String cidB, String filed) {
        Map<String, Map<String, List<PlatformComparison>>> data = activityMediaSlotAnalysisService.contactTypeComposition(cidA, cidB, filed);
        return Result.success(data);
    }

    @GetMapping("/contactTypeCompositionDownload")
    public void contactTypeCompositionDownload(String cidA, String cidB, String filed, HttpServletResponse response) throws IOException {
        activityMediaSlotAnalysisService.contactTypeCompositionDownload(cidA, cidB, filed, response);
    }

    @GetMapping("/contactDistribution")
    public Result contactDistribution(String cidA, String cidB, String filed, String media){
        Map<String, List<PlatformComparison>> data = activityMediaSlotAnalysisService.contactDistribution(cidA,cidB,filed,media);
        return Result.success(data);
    }

    @GetMapping("/upload")
    public void upload() {
        System.out.println(upload);
    }


}
